package com.neuedu.servlet;

import com.neuedu.dao.DeptDao;
import com.neuedu.entity.Dept;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 *  http://localhost:8080/web/form
 *
 *  地址栏直接传  GET
 *      http://localhost:8080/web/form?参数名字1=value1&param2=value2
 *      http://localhost:8080/web/form?deptno=80&dname=DEV&loc=Harbin
 *  form表单   method : GET  POST
 *
 */
@WebServlet(urlPatterns = "/form")
public class FormServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //接收数据，保存到数据库
        String deptno = req.getParameter("deptno");
        String dname = req.getParameter("dname");
        String loc = req.getParameter("loc");

        Dept dept = new Dept(
                Integer.parseInt(deptno),
                dname,
                loc
                );

        DeptDao deptDao = new DeptDao();
        int insert = deptDao.insert(dept);

        System.out.println("insert = " + insert);

    }
}
